<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>业务处理-退货申请</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>退货申请</a></div>
			<div class="search">
			<form action="<%=basePath %>returnRequest/listReturnRequest.do" method="post" class="form">
				<input type="hidden" name="currentPage" value="1">
				<p>
					<label>单号</label>
					<input type="text" class="form-control" name="applicationNo" value="${returnRequestPage.applicationNo }"></input>
					<label>状态</label>
					<select name="status" class="form-control select">
						<option value="">全部</option>
						<option value="0" <c:if test="${returnRequestPage.status==0}">selected</c:if>>未提交</option>
						<option value="1" <c:if test="${returnRequestPage.status==1}">selected</c:if>>已提交</option>
						<option value="2" <c:if test="${returnRequestPage.status==2}">selected</c:if>>审核中</option>
						<option value="3" <c:if test="${returnRequestPage.status==3}">selected</c:if>>已通过</option>
						<option value="4" <c:if test="${returnRequestPage.status==4}">selected</c:if>>未通过</option>
					</select>
					<label>退货说明</label>
					<input class="form-control doubleWidth" type="text" name="returnPolicy" value="${returnRequestPage.returnPolicy }"></input>
				</p>
					<p>
					<label>提交人</label>
					<input type="text" class="form-control" name="submitterName" value="${returnRequestPage.submitterName }">
					<label>创建人</label>
					<input type="text" class="form-control" name="createPersonName" value="${returnRequestPage.createPersonName }">
					<label>提交时间</label>
					<input type="text" class="form-control" name="commitTime1" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" value="${returnRequestPage.commitTime1 }"></input>
					<label>至</label>
					<input type="text" class="form-control" name="commitTime2" readonly onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})" value="${returnRequestPage.commitTime2 }"></input>
				</p>
				<p>
					<label>仓库</label>
					<select name="warehouseManagementID" class="form-control select">
						<option value="">全部</option>
						<c:forEach	items="${warehouseList }" var="warehouse">
							<option value="${warehouse.warehousemanagementid }">${warehouse.warehousename }</option>
						</c:forEach>
					</select>
					<span class="btn">
						<input type="submit" class="btn btn1" value="查询"></input>
						<input type="button" class="btn btn2" value="清空" onclick="clearSearchParam();"></input>
						<input type="button" class="btn btn1" value="详情" onclick="toEditReturnRequest();"></input>
						<input type="button" class="btn btn_danger" value="删除" onclick="toDeleteReturnRequest();"></input>
						<c:if test="${isAdd }">
						<input type="button" value="新增" class="btn btn1" onclick="addReturnRequest();"></input>
						</c:if>
					</span>
				</p>
				</form>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:180px;">操作</th>
							<th>单号</th>
							<th>退货说明</th>
							<th>品项数</th>
							<th>状态</th>
							<th>提交时间</th>
							<th>创建人</th>
							<th>提交人</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${requestList }" var="request" varStatus="i">
							<tr id="${request.returnRequestID }" onclick="selectRow(this);">
								<td>
								<label class="radio"><input type="radio" name="operateReturnRequest" value="${request.returnRequestID }"><span class="radio_icon"></span></label></td>
								<td>
									<a class="btn btn-xs btn1" onclick="editReturnRequest(${request.returnRequestID });">详情</a>
								<c:if test="${request.status=='0' }">
									<a class="btn btn-xs btn2" onclick="confirmSubmitReturnRequest(${request.returnRequestID });">提交</a>
									<a class="btn btn-xs btn_danger" onclick="confirmDeleteReturnRequest(${request.returnRequestID });">删除</a>
								</c:if>
								</td>
								<td><a onclick="editReturnRequest(${request.returnRequestID });">${request.applicationNo}</a></td>
								<td>${request.returnPolicy }</td>
								<td>${request.number }</td>
								<td>
									<c:if test="${request.status==0 }">未提交</c:if>
									<c:if test="${request.status==1 }">已提交</c:if>
									<c:if test="${request.status==2 }">审核中</c:if>
									<c:if test="${request.status==3 }">已通过</c:if>
									<c:if test="${request.status==4 }">未通过</c:if>
								</td>
								<td><fmt:formatDate value="${request.commitTime }" pattern="yyyy-MM-dd HH:mm:ss" /></td>
								<td>${request.submitterName }</td>
								<td>${request.submitterName }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>My97DatePickers/WdatePicker.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
	
	function clearSearchParam(){
		$(".search input:text").val("");
		$(".search select").val("");
	}
	
	function selectRow(obj){
		$(obj).find('input:radio[name="operateReturnRequest"]')[0].checked=true;
	}
	
	function toEditReturnRequest(){
		var radio=$('input:radio[name="operateReturnRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要编辑的退货申请！");
			return;
		}
		editReturnRequest(radio.val());
	}
	
	function editReturnRequest(returnRequestID){
		location.href="<%=basePath %>returnRequest/toEdit.do?returnRequestID="+returnRequestID;
	}
	
	function addReturnRequest(returnRequestID){
		location.href="<%=basePath %>returnRequest/toAdd.do?";
	}
	
	function toDeleteReturnRequest(){
		var radio=$('input:radio[name="operateReturnRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("删除提示","请先选中需要删除的退货申请！");
			return;
		}
		confirmDeleteReturnRequest(radio.val());
	}
		
	function confirmDeleteReturnRequest(id){
		var delFunc=function(){
			$.ajax({
				url:"<%=basePath %>returnRequest/delete.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "returnRequestID="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("删除提示","退货申请已删除！",Prompt.refresh);
					}else{
						Prompt.alert("提示","退货申请删除失败！");
					}
				},
				error :function(){
					Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要删除该退货申请吗?删除后无法恢复",delFunc);
	}
	
	function toSubmitReturnRequest(){
		var radio=$('input:radio[name="operateReturnRequest"]:checked');
		if(!radio.val()){
			Prompt.alert("提示","请先选中需要提交的退货申请！");
			return;
		}
		confirmSubmitReturnRequest(radio.val());
	}
		
	function confirmSubmitReturnRequest(id){
		var submitFunc=function(){
			$.ajax({
				url:"<%=basePath %>returnRequest/submit.do",
				type:"post",
				async : false,
				dataType:"json",
				data : "returnRequestID="+id,
				success:function(data){
					if(data.result=="success"){
						Prompt.alert("提示","退货申请已提交！",Prompt.refresh);
					}else{
						Prompt.alert("提示","退货申请提交失败！"+data.error);
					}
				},
				error :function(){
					Prompt.alert("提示","服务器无响应，请刷新页面后重试！");
				}
			});
		}
		Prompt.confirm("提示","确认要提交该退货申请吗?",submitFunc);
	}
	</script>
</body>
</html>